package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.UserRole;
import com.xinhe.web.service.UserRoleService;
import com.xinhe.web.vo.UserRoleModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(value = "系统用户角色", tags = {"系统用户角色"})
@RestController
@RequestMapping(value = {"/userRole"}, produces = {"application/json;charset=UTF-8"})
public class UserRoleController
{
    @Autowired
    private UserRoleService userRoleService;

    @ApiOperation(httpMethod = "GET", value = "分页查询系统用户角色")
    @RequestMapping({"/pageUserRole"})
    public QueryResults<UserRole> pageUserRole(Long userId, Long roleId, int pageNum, int pageSize) {
        return this.userRoleService.pageUserRole(userId,roleId,pageNum,pageSize);
    }
    @ApiOperation(httpMethod = "POST", value = "保存系统用户角色")
    @RequestMapping({"/saveUserRole"})
    public Result saveUserRole(@Valid UserRoleModel model, BindingResult bind) {
        return this.userRoleService.saveUserRole(model);
    }

    @ApiOperation(httpMethod = "GET", value = "删除系统用户角色")
    @ApiImplicitParam(name = "userRoleId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/deleteUserRole"})
    public Result deleteUserRole(Long userRoleId) {
        return this.userRoleService.delete(userRoleId);
    }

    @ApiOperation(httpMethod = "GET", value = "系统用户角色详情")
    @ApiImplicitParam(name = "userRoleId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/detailUserRole"})
    public Result detailUserRole(Long userRoleId) {
        return this.userRoleService.findById(userRoleId);
    }
}